<?php

if (!defined('BASEPATH') &&
    strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')
    exit('Niente da vedere');
    
    
include 'config.php';
include 'functions.php';
session_start();
$cart = new Cart();
$db = new db();
    
    if (  strcmp( $_POST['request_type'] , "complete" ) == 0 ){
    	
    	echo json_encode( array("request_completed" => $db->set_request_complete($_POST['request_id']) ));
    }
    elseif (  strcmp( $_POST['request_type'] , "delete" ) == 0 ){
    	
    	echo json_encode( array("request_completed" => $db->delete_request($_POST['request_id']) ));
    }
    elseif (  strcmp( $_POST['request_type'] , "change_password" ) == 0 ){
    	$email = $_SESSION['admin_email'];
    	$current_passwd = $_POST['current_password'];
    	$new_password = $_POST['new_password'];
    	
    	if ( strcmp($new_password, $_POST['new_password_confirm']) != 0 || strlen($new_password) <5 )
    		return json_encode(array("changed_password" => FALSE));
    		
    	$result = $db->query("UPDATE admins SET password = '$new_password'  WHERE
    			`email` =  '$email'
    			AND `password` = '$current_passwd'");
    	
    	echo json_encode(array( "password_changed" => $result ));
    	
    }
    
    
?>